import {PlusOutlined} from '@ant-design/icons';
import {
    ModalForm,
    ProForm,
    ProFormDateRangePicker,
    ProFormSelect,
    ProFormText,
} from '@ant-design/pro-components';
import {Button, Form, message} from 'antd';
import {updateChatter} from "@/services/chatter";

const waitTime = (time: number = 100) => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(true);
        }, time);
    });
};

export default (props) => {
    const {record, reloadTable} = props;
    const [form] = Form.useForm<{ name: string; company: string }>();
    return (
        <ModalForm<{
            name: string;
            company: string;
        }>
            title="Update"
            trigger={
                <a type="primary">
                    Update
                </a>
            }
            form={form}
            autoFocusFirstInput
            modalProps={{
                destroyOnClose: true,
                onCancel: () => console.log('run'),
            }}
            submitTimeout={2000}
            onFinish={async (values) => {
                // await waitTime(2000);
                // console.log(values.name);
                // message.success('提交成功');
                const params = {
                    "nickName": values.name,
                    "chatterCode": record.chatterCode,
                    "status": record.status,
                    "password": values.password,
                };
                console.log(values,params);
                updateChatter(params).then(res => {
                    reloadTable();
                })


                return true;
            }}
        >
            <ProFormText
                name="name"
                label="current name:"
                placeholder="input new one"
                initialValue={record.nickName}
            />

            <ProFormText
                name="password"
                label="current pswd:"
                placeholder="input new one"
                initialValue={record.password}
            />
        </ModalForm>
    );
};